package yxy.cherry.battle.module.affix;

import yxy.cherry.battle.Fighter;
import yxy.cherry.battle.module.record.Record;

import java.util.*;

/** 词缀上下文 */
public class AffixContext {
	private boolean 跳过普通技能;
	private boolean 跳过怒气技能;
	private boolean 无视防御;

	private boolean 附加行动中;

	private Set<Fighter> 怒气变动武将 = new HashSet<>();

	private AffixAction 攻击行动 = new AffixAction();

	private AffixAction 治疗行动 = new AffixAction();

	private LinkedList<AffixAction> 附加行动List = new LinkedList<>();
	private AffixAction 附加行动;

	public void set跳过普通技能(boolean 跳过普通技能) {
		this.跳过普通技能 = 跳过普通技能;
	}

	public boolean is跳过普通技能() {
		return 跳过普通技能;
	}

	public void set跳过怒气技能(boolean 跳过怒气技能) {
		this.跳过怒气技能 = 跳过怒气技能;
	}

	public boolean is跳过怒气技能() {
		return 跳过怒气技能;
	}

	public void add怒气变动武将(Fighter fighter) {
		怒气变动武将.add(fighter);
	}

	public Collection<Fighter> get怒气变动武将() {
		return 怒气变动武将;
	}

	public void set附加行动中(boolean 附加行动中) {
		this.附加行动中 = 附加行动中;
	}

	public boolean is附加行动中() {
		return 附加行动中;
	}

	public boolean is无视防御() {
		return 无视防御;
	}

	public void set无视防御(boolean 无视防御) {
		this.无视防御 = 无视防御;
	}

	public AffixAction get攻击行动() {
		return 攻击行动;
	}

	public AffixAction get治疗行动() {
		return 治疗行动;
	}

	public AffixAction add附加行动(Fighter 行动者, Collection<Fighter> 目标, AffixActionClass 行动类型) {
		AffixAction action = new AffixAction();
		action.set行动者(行动者);
		action.setTargets(目标);
		action.add行动类型(行动类型);
		this.附加行动List.add(action);
		return action;
	}

	public Collection<AffixAction> get附加行动List() {
		return 附加行动List;
	}

	public void set附加行动(AffixAction 附加行动) {
		this.附加行动 = 附加行动;
	}

	public AffixAction get附加行动() {
		return 附加行动;
	}

	public void reset() {
		怒气变动武将.clear();
		跳过普通技能 = false;
		跳过怒气技能 = false;
		无视防御 = false;
		附加行动中 = false;
		攻击行动.reset();
		治疗行动.reset();
		附加行动List.clear();
		附加行动 = null;
	}

	static public enum AffixActionClass {
		普通技能, 怒气技能, 物理攻击, 法术攻击, 追加攻击, 主动治疗, 复活, 加BUFF, 反击, 有伤害, 有暴击, 有击杀;
	}

	static public class AffixAction {
		private Fighter 行动者;

		private Set<AffixActionClass> 行动类型 = new HashSet<>();
		private Set<Fighter> 死掉的武将 = new HashSet<>();// 本次行动死掉的武将

		public Collection<Fighter> get死掉的武将() {
			return 死掉的武将;
		}

		private LinkedHashMap<Fighter, AffixTarget> 目标们 = new LinkedHashMap<>();

		private Fighter 针对目标;

		private boolean 无视防御;
		private int 附加比例 = 0;

		public void set行动者(Fighter 行动者) {
			this.行动者 = 行动者;
		}

		public Fighter get行动者() {
			return 行动者;
		}

		public void add死掉的武将(Fighter fighter) {
			死掉的武将.add(fighter);
		}

		public void add行动类型(AffixActionClass action) {
			this.行动类型.add(action);
		}

		public Set<AffixActionClass> get行动类型() {
			return 行动类型;
		}

		public Fighter get针对目标() {
			return 针对目标;
		}

		public void set针对目标(Fighter 针对目标) {
			this.针对目标 = 针对目标;
		}

		public void clear目标们() {
			目标们.clear();
		}

		public Collection<AffixTarget> get目标们() {
			return 目标们.values();
		}

		public Collection<Fighter> get目标们Fighter() {
			ArrayList<Fighter> list = new ArrayList<>();
			for (AffixTarget target : get目标们()) {
				list.add(target.get目标());
			}
			return list;
		}

		public void set无视防御(boolean 无视防御) {
			this.无视防御 = 无视防御;
		}

		public boolean is无视防御() {
			return 无视防御;
		}

		public void set附加比例(int 附加比例) {
			this.附加比例 = 附加比例;
		}

		public int get附加比例() {
			return 附加比例;
		}

		public void addTarget(Fighter fighter) {
			AffixTarget target = new AffixTarget(fighter);
			目标们.put(fighter, target);
		}

		public void setTargets(Collection<Fighter> targets) {
			StringBuffer sb = new StringBuffer();
			sb.append("设定目标：");
			for (Fighter fighter : targets) {
				sb.append(fighter.getName() + ",");
			}
			Record.stdout(sb.toString());
			this.目标们.clear();
			for (Fighter fighter : targets) {
				AffixTarget target = new AffixTarget(fighter);
				目标们.put(fighter, target);
			}
		}

		public AffixTarget getTarget(Fighter fighter) {
			return this.目标们.get(fighter);
		}

		public long 总伤害() {
			long totalDamage = 0L;
			for (AffixTarget target : get目标们()) {
				totalDamage += target.总伤害();
			}
			return totalDamage;
		}

		public void set援护(AffixTarget protection, Fighter actor) {
			this.目标们.remove(protection.get目标());
			protection.set援护对象(actor);
			this.目标们.put(protection.get目标(), protection);
		}

		public void reset() {
			行动者 = null;
			针对目标 = null;
			死掉的武将.clear();
			目标们.clear();
			行动类型.clear();
			无视防御 = false;
			附加比例 = 10000;
		}

	}

	static public class AffixTarget {
		private Fighter 目标;
		private Fighter 援护对象;

		private ArrayList<Long> 伤害流 = new ArrayList<>();
		private ArrayList<Long> 效果流 = new ArrayList<>();

		private Long 治疗量;
		private ArrayList<Long> baseDamageList = new ArrayList<>();//基础伤害
		private Double baseAddDamagePer = 1.0;//基础的增伤比例

		public Double getBaseAddDamagePer(){
			return baseAddDamagePer;
		}

		public void setBaseAddDamagePer(Double baseAddDamagePer){
			this.baseAddDamagePer = baseAddDamagePer;
		}

		public ArrayList<Long> getBaseDamageList() {
			return baseDamageList;
		}

		public void setBaseDamageList(ArrayList<Long> baseDamageList) {
			this.baseDamageList = baseDamageList;
		}

		public AffixTarget(Fighter 目标) {
			this.目标 = 目标;
		}

		public void set援护对象(Fighter 援护者) {
			this.援护对象 = this.目标;
			this.目标 = 援护者;
		}

		public Fighter get目标() {
			return 目标;
		}

		public Fighter get援护对象() {
			return 援护对象;
		}

		public ArrayList<Long> get效果流() {
			return 效果流;
		}

		public ArrayList<Long> get伤害流() {
			return 伤害流;
		}

		public void set伤害流(ArrayList<Long> 伤害流) {
			this.伤害流 = 伤害流;
		}

		public void set效果流(ArrayList<Long> 效果流) {
			this.效果流 = 效果流;
		}

		public void set治疗量(Long 治疗量) {
			this.治疗量 = 治疗量;
		}

		public Long get治疗量() {
			return 治疗量;
		}

		public long 总伤害() {
			long totalDamage = 0L;
			for (Long damage : 伤害流) {
				totalDamage += damage;
			}
			return totalDamage;
		}

	}

}
